package com.ruoyi.training.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.A01ResTeacher;
import com.ruoyi.training.service.IA01ResTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 师资库Controller
 * 
 * @author WorrilessGo
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/teacher")
public class A01ResTeacherController extends BaseController
{
    @Autowired
    private IA01ResTeacherService a01ResTeacherService;

    /**
     * 查询师资库列表
     */
    @RequiresPermissions("training:teacher:list")
    @GetMapping("/list")
    public TableDataInfo list(A01ResTeacher a01ResTeacher)
    {
        startPage();
        List<A01ResTeacher> list = a01ResTeacherService.selectA01ResTeacherList(a01ResTeacher);
        return getDataTable(list);
    }

    /**
     * 导出师资库列表
     */
    @RequiresPermissions("training:teacher:export")
    @Log(title = "师资库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, A01ResTeacher a01ResTeacher)
    {
        List<A01ResTeacher> list = a01ResTeacherService.selectA01ResTeacherList(a01ResTeacher);
        ExcelUtil<A01ResTeacher> util = new ExcelUtil<A01ResTeacher>(A01ResTeacher.class);
        util.exportExcel(response, list, "师资库数据");
    }


    /**
     * 导出师资库列表
     */
//    @RequiresPermissions("training:teacher:export")
//    @Log(title = "师资库", businessType = BusinessType.EXPORT)
    @PostMapping("/exportModel")
    public void exportModel(HttpServletResponse response)
    {
        List<A01ResTeacher> list = new ArrayList<>();
        ExcelUtil<A01ResTeacher> util = new ExcelUtil<A01ResTeacher>(A01ResTeacher.class);
        util.exportExcel(response, list, "师资库数据");
    }




    /**
     * 导入资源库数据
     */
    @RequiresPermissions("training:teacher:import")
    @Log(title = "师资库", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
        {
        ExcelUtil<A01ResTeacher> util = new ExcelUtil<A01ResTeacher>(A01ResTeacher.class);
        List<A01ResTeacher> list = util.importExcel(file.getInputStream(),1);
        int message = a01ResTeacherService.batchInsertA01ResTeacher(list);
        return toAjax(message);
    }


    /**
     * 获取师资库详细信息
     */
    @RequiresPermissions("training:teacher:query")
    @GetMapping(value = "/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") String teacherId)
    {
        return success(a01ResTeacherService.selectA01ResTeacherByTeacherId(teacherId));
    }

    /**
     * 新增师资库
     */
    @RequiresPermissions("training:teacher:add")
    @Log(title = "师资库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody A01ResTeacher a01ResTeacher)
    {
        return toAjax(a01ResTeacherService.insertA01ResTeacher(a01ResTeacher));
    }

    /**
     * 修改师资库
     */
    @RequiresPermissions("training:teacher:edit")
    @Log(title = "师资库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody A01ResTeacher a01ResTeacher)
    {
        return toAjax(a01ResTeacherService.updateA01ResTeacher(a01ResTeacher));
    }

    /**
     * 删除师资库
     */
    @RequiresPermissions("training:teacher:remove")
    @Log(title = "师资库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable String[] teacherIds)
    {
        return toAjax(a01ResTeacherService.deleteA01ResTeacherByTeacherIds(teacherIds));
    }
}
